//
//  SubTableVC.m
//  SomeListDemo
//
//  Created by 孙哈哈 on 2017/10/20.
//  Copyright © 2017年 SunDe. All rights reserved.
//

#import "SubTableVC.h"

@interface SubTableVC () <UIScrollViewDelegate>

@end

@implementation SubTableVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.rowHeight = 60.0f;
    self.tableView.estimatedRowHeight = 60.0f;
    self.tableView.tableFooterView = [[UIView alloc] init];
    
    self.tableView.backgroundColor = [UIColor purpleColor];
    
    if (@available(iOS 11.0, *)) {
//        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
    
    self.canScroll = NO;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    
    if (self.canScroll == NO) {
        scrollView.contentOffset = CGPointZero;
    }
    
    if (scrollView.contentOffset.y < 0 ) {
        self.canScroll = NO;
        scrollView.contentOffset = CGPointZero;
        self.block();
    }
}

- (void)handlerBlock:(notiBlock)block {
    self.block = block;
}

#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 60;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellID"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellID"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    cell.textLabel.text = [NSString stringWithFormat:@"第%ld个 CELL", indexPath.row];
    
    if (indexPath.row % 2 == 0) {
        cell.contentView.backgroundColor = [UIColor greenColor];
    }else{
        cell.contentView.backgroundColor = [UIColor whiteColor];
    }
    
    return cell;
}

@end
